"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProtoManager = void 0;
const Singleton_1 = require("../../../engine/Singleton");
const Logger_1 = require("../../../engine/utils/Logger");
class ProtoManager extends (0, Singleton_1.default)() {
    encode(proto_ctor, data) {
        if (!data) {
            return null;
        }
        try {
            let buffer_data = proto_ctor.encode(proto_ctor.create(data)).finish();
            return buffer_data;
        }
        catch (error) {
            Logger_1.Logger.error('encode fail protoName:' + proto_ctor.name + ' data:' + JSON.stringify(data));
            return null;
        }
    }
    decode(proto_ctor, data) {
        if (!data) {
            return null;
        }
        try {
            return proto_ctor.decode(data);
        }
        catch (error) {
            Logger_1.Logger.error('dncode fail protoName:' + proto_ctor.name);
            return null;
        }
    }
}
exports.ProtoManager = ProtoManager;
